package test;
    //
public class MyCircularQueue {
    private int[] elum;
    private int front;
    private int rear;



    public MyCircularQueue(int k) {
        //采用的是浪费一个空间的方法来判断是否已满，所以要多一个空间
        this.elum = new int[k+1];
    }

    public boolean enQueue(int value) {
        if(isEmpty()){
            return false;
        }
        elum[rear]=value;
        rear = (rear+1)%elum.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front = (front+1)%elum.length;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return elum[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int index = (rear == 0)?elum.length-1:rear-1;
        return elum[rear];
    }

    public boolean isFull() {
        if((rear+1)%elum.length==front){
            return true;
        }
        return false;
    }

    public boolean isEmpty() {
        if(rear==front){
            return true;
        }
        return false;
    }
}
